package com.ruoyi.primer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.primer.domain.Primer;
import com.ruoyi.primer.service.IPrimerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 引物信息Controller
 * 
 * @author dongke
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/primer/primer")
public class PrimerController extends BaseController
{
    @Autowired
    private IPrimerService primerService;

    /**
     * 查询引物信息列表
     */
    @PreAuthorize("@ss.hasPermi('primer:primer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Primer primer)
    {
        startPage();
        List<Primer> list = primerService.selectPrimerList(primer);
        return getDataTable(list);
    }

    /**
     * 导出引物信息列表
     */
    @PreAuthorize("@ss.hasPermi('primer:primer:export')")
    @Log(title = "引物信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Primer primer)
    {
        List<Primer> list = primerService.selectPrimerList(primer);
        ExcelUtil<Primer> util = new ExcelUtil<Primer>(Primer.class);
        util.exportExcel(response, list, "引物信息数据");
    }

    /**
     * 获取引物信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('primer:primer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(primerService.selectPrimerById(id));
    }

    /**
     * 新增引物信息
     */
    @PreAuthorize("@ss.hasPermi('primer:primer:add')")
    @Log(title = "引物信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Primer primer)
    {
        return toAjax(primerService.insertPrimer(primer));
    }

    /**
     * 修改引物信息
     */
    @PreAuthorize("@ss.hasPermi('primer:primer:edit')")
    @Log(title = "引物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Primer primer)
    {
        return toAjax(primerService.updatePrimer(primer));
    }

    /**
     * 删除引物信息
     */
    @PreAuthorize("@ss.hasPermi('primer:primer:remove')")
    @Log(title = "引物信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(primerService.deletePrimerByIds(ids));
    }
}
